package com.wbc.smartHome.dao;

import com.wbc.smartHome.model.Commodity;
import com.wbc.smartHome.model.CommunityActivities;
import com.wbc.smartHome.model.CommunityActivitiesLabel;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface CommunityActivitiesDao {
    List<CommunityActivities> getCommunityActivitiesList();

    @Insert("insert into community_activities(title,person_num,img,organizers,phone,address,area,note,content,start_time,oper_time,adminid)values (#{title},#{personNum},#{img},#{organizers},#{phone},#{address},#{area},#{note},#{content},#{startTime},now(),#{adminid})")
    void setCommunityActivities(CommunityActivities communityActivities);

    @Select("SELECT id,name,typeid,img,address,first_price,now_price,content,oper_time  \n" +
            "FROM commodity \n" +
            "where (first_price - now_price) >=50\n" +
            "ORDER BY (first_price - now_price) desc;\n" +
            "\n")
    List<Commodity> getSpecialOffer();


    @Select("select id,title,person_num,img,organizers,phone,address,area,note,content,start_time,oper_time,adminid FROM community_activities where id = #{id}")
    CommunityActivities getCommunityActivitiesById(Integer id);

    @Select("SELECT id,title,person_num,img,organizers,phone,address,area,note,content,oper_time  \n" +
            "FROM community_activities  \n" +
            "WHERE id = (  \n" +
            "    SELECT activitiesid  \n" +
            "    FROM communityactivitieslabel_communityactivities  \n" +
            "    WHERE labelid = #{labelId}  \n" +
            ")")
    List<CommunityActivities> getCommunityActivitiesLabelNameByLabelId(Integer labelId);



    List<CommunityActivities> communityActivitiesList(CommunityActivities communityActivities);

    @Delete("delete from community_activities where id = #{id}")
    void delete(int id);

    @Insert("insert into communityactivitieslabel_communityactivities(labelid,activitiesid,amdinid,oper_time)values(#{labelId},#{communityActivitiesId},#{adminId},now())")
    void setLabelRelationship(Integer labelId, int communityActivitiesId, int adminId);

    @Select("select id,name from communityactivities_label")
    List<CommunityActivitiesLabel> getCommunityActivitiesLabelList();

    @Select("select id from community_activities where title = #{title} ")
    int getCommunityActivitiesIdByTitle(String title);

    @Update("update community_activities set title = #{title},person_num=#{personNum},img=#{img},organizers=#{organizers},phone=#{phone},address=#{address},area=#{area},note=#{note},content=#{content},adminid=#{adminId},start_time=#{startTime},oper_time=now() where id =#{id}")
    void updateCommunityActivities(CommunityActivities communityActivities);

    @Delete("delete from communityactivitieslabel_communityactivities where activitiesid = #{id}")
    void deleteLabelByActivitiesId(Integer id);

    @Insert("insert into communityactivitieslabel_communityactivities(labelid,activitiesid,amdinid,oper_time)values (#{labelId},#{activitiesId},#{adminId},now())")
    void addLabelByActivitiesId(Integer labelId, Integer activitiesId, int adminId);

    List<CommunityActivities> getRecommendCommunityActivities();
}
